# -*- coding: utf-8 -*-
# @Time : 2024/2/19 18:16
# @Author : ZH
# @File : 33.py
# @Software: PyCharm
class Solution(object):

    def aa(self, nums_, target):
        l = 0
        r = len(nums_) - 1
        z = int((r+l)/2)
        while l <= r:
            if nums_[z] > target:
                r = z - 1
            elif nums_[z] < target:
                l = z + 1
            else:
                return z
            z = int((r+l)/2)

    def search(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        if target not in nums: return -1
        # 先对整个数据进行排序分组
        index_ = 0
        for index in range(1, len(nums)):
            if nums[index] < nums[index - 1]:
                index_ = index
                break

        if index_ == 0:
            return self.aa(nums_=nums, target=target)

        if nums[0] >= target:
            # 说明在后面
            return self.aa(nums_=nums[index_:], target=target) + index_
        else:
            return self.aa(nums_=nums[:index_], target=target) + index_


if __name__ == '__main__':
    so = Solution()
    nums = [3, 1]
    target = 3
    z = so.search(nums=nums, target=target)
    print(z)
